<template>
  <div class="myContainer">
    <!-- 头部标题 start -->  
    <el-row class="myBorderBottom">
      <el-col :span="7" class="myTitleText myLineHeight_40px">
        {{title}}
      </el-col>
      <el-col :span="17" class="myTextAlignRight">
        <!-- <el-button type="primary" class="myBgGreen" @click="add">新增</el-button> -->
      </el-col>
    </el-row>
    <!-- 头部标题 end -->
    <el-row :gutter="10" class="myPaddingTop_10px">
      <el-col :span="6">
        <template>
          <el-cascader
            placeholder="全部项目/小区"
            :options="regionOptions"
            v-model="regionOptSelected">
          </el-cascader>
        </template>
      </el-col>
      <el-col :span="4">
        <template>
          <el-select v-model="statusSelected"
            clearable
            placeholder="全部借用状态">
            <el-option
              v-for="item in status"
              :key="item.label"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </template>
      </el-col>
      <el-col :span="6">
        <el-date-picker
          v-model="time"
          type="daterange"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </el-col>
      <el-col :span="3">
        <el-button type="primary" @click="search">查询</el-button>
      </el-col>
    </el-row>
    
    <el-row class="myPaddingTop_10px">
      <el-col :span="24">
        <template>
          <el-table
            border
            :data="list"
            :stripe = true
            v-loading="loading"
            style="width: 100%">
            <el-table-column
              label="借出单号"
              prop="lend_no">
            </el-table-column>
            <el-table-column
              label="当前状态">
              <template scope="scope">
                <span v-if="scope.row.lend_status==1">借出</span>
                <span v-if="scope.row.lend_status==2">已归还</span>
              </template>
            </el-table-column>
            <el-table-column
              label="借出日期"
              prop="lend_time">
              <template scope="scope">
                <span>{{scope.row.lend_time | getTime}}</span>
              </template>
            </el-table-column>
            <el-table-column
              label="借用人"
              prop="user_name">
            </el-table-column>
            <el-table-column
              label="预计归还日期"
              prop="expect_return_time">
              <template scope="scope">
                <span>{{scope.row.expect_return_time | getTime}}</span>
              </template>
            </el-table-column>
            <el-table-column
              label="实际归还日期"
              prop="actual_return_time">
              <template scope="scope">
                <span>{{scope.row.actual_return_time | getTime}}</span>
              </template>
            </el-table-column>
            <el-table-column
              label="资产条码"
              prop="property_code">
            </el-table-column>
            <el-table-column
              label="资产名称"
              prop="property_name">
            </el-table-column>
            <el-table-column
              label="规格型号"
              prop="property_spec">
            </el-table-column>
            <el-table-column
              label="借用创建人"
              prop="lend_creator_name">
            </el-table-column>
            <el-table-column
              label="借用创建时间"
              prop="lend_create_time">
            </el-table-column>
            <el-table-column
              label="归还创建人"
              prop="return_creator_name">
            </el-table-column>
            <el-table-column
              label="归还创建时间"
              prop="return_create_time">
            </el-table-column>
          </el-table>
          </el-table>
        </template>
      </el-col>
    </el-row>
    
    <div class="block">                    
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="page_num"
        :page-sizes="[10, 15]"
        :page-size="page_size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </div>

  </div>
</template>     
  
<style scoped>
  .myBorderBottom{
    border-bottom:1px solid #dbdbdb;
    padding-bottom: 5px;
  }
  .myTextAlignRight{
    text-align: right;
  }
  .myContainer{
    background: #fff;
    padding: 10px;
  }
  .myTitleText{
    font-weight: 500;
    font-size: 16px;
  }
  .myLineHeight_40px{
    line-height: 40px;
  }
  .myPaddingTop_10px{
    padding-top: 10px;
  }  
  .myred{
    color: #f00;
    font-size: 12px;
  }
  .myMarginBottom_10px{
    margin-bottom: 10px;
  }
  .myLeftMsg{
    line-height: 40px;
    text-align: right;
  }
  .RepairDigTab{
    width: 100%;
    border: 1px solid #e6ebf5;
    padding: 0;
    border-spacing: 0;
    border-collapse: collapse;
  }
  .RepairDigTab tr,.RepairDigTab td{
    border: 1px solid #e6ebf5;
  }
  .RepairDigTab td{
    width: 25%;
    height: 40px;
  }
</style>

<script>
  import { extractAreaIds } from '@/utils/misc';
  import { getRegion } from '@/utils/localstorage';
  import { getRepairList , getAssetsDetail , lendbackAsset } from "@/api/assets";
  export default {
    data(){
      return{
        title:"借用&归还",
        page_num:1,
        page_size:10,
        total:null,
        list:[],
        loading:false,
        regionOptions: [],
        regionOptSelected: [],
        statusSelected:"",
        status:[
          {label:"借出",value:"1"},
          {label:"已归还",value:"2"}
        ],
        time:[]
      }
    },
    components: {

    },
    created(){
      document.title=this.title;
      this.regionOptions = getRegion();
      this.regionOptSelected.push(this.regionOptions[0].value,this.regionOptions[0].children[0].value,this.regionOptions[0].children[0].children[0].value);

      this.ongetLendbackAssetList();
    },
    computed: {
      areaIds() {
        return extractAreaIds(this.regionOptSelected, this.regionOptions);
      }
    },
    filters:{
      getTime(val){
        return val?val.split(' ')[0]:'';
      }
    },
    watch: {
      
    },
    methods:{
      handleSizeChange(val) {//每页条数控制
        this.page_size = val;
        this.ongetLendbackAssetList();
      },
      handleCurrentChange(val) {//每页
        this.page_num = val;
        this.ongetLendbackAssetList();
      },
      search(){
        this.ongetLendbackAssetList();
      },
      ongetLendbackAssetList(){
        let vm=this;
        let params={
          area_id:vm.areaIds,
          status:vm.statusSelected,
          start_time:vm.time?vm.time[0]:'',
          end_time:vm.time?vm.time[1]:'',
          page_num:vm.page_num,
          page_size:vm.page_size
        }
        vm.loading=true;
        lendbackAsset(params).then(response =>{
          let res=response.data;
          vm.list=res.rows;
          vm.page_size=res.page_size;
          vm.page_num=vm.page_num;
          vm.total=res.total;
          vm.loading=false;
        }).catch(error => {
          vm.loading=false;
          vm.$message.error("拉取列表失败！"+error.response.data.error_msg);
        })
      },

    }
}
</script>

